package com.b2c.controller;

import com.b2c.annotation.ApiLimit;
import com.b2c.pojo.vo.CodeEmailVo;
import com.b2c.pojo.vo.CodePhoneVO;
import com.b2c.pojo.vo.EmailVo;
import com.b2c.pojo.vo.PhoneVo;
import com.b2c.service.UserService;
import com.b2c.service.impl.UserServiceImpl;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.Result;

import javax.mail.MessagingException;
import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserLoginController {

    @Autowired
    private UserService userService;

    /**
     * 手机号登录
     *
     * @param codePhoneVO
     * @return
     */
    @GetMapping("/login/phone")
    public Result adminLoginPhone(CodePhoneVO codePhoneVO) {
        return userService.userLoginPhone(codePhoneVO);
    }

    /**
     * 邮箱登录
     *
     * @param codeEmailVo
     * @return
     */
    @GetMapping("/login/email")
    public Result adminLoginEmail(CodeEmailVo codeEmailVo) {
        return userService.userLoginEmail(codeEmailVo);
    }


    /**
     * 绑定手机号
     *
     * @param codePhoneVO
     * @return
     */
    @PutMapping("/bind/phone")
    public Result bindPhone(CodePhoneVO codePhoneVO) {
        return userService.bindPhone(codePhoneVO);
    }

    /**
     * 绑定邮箱
     *
     * @param codeEmailVo
     * @return
     */
    @PutMapping("/bind/email")
    public Result bindEmail(CodeEmailVo codeEmailVo) {
        return userService.bindEmail(codeEmailVo);
    }

    /**
     * 通过手机号注册
     *
     * @param codePhoneVO
     * @return
     */
    @PostMapping("/register/phone")
    public Result registerByPhone(CodePhoneVO codePhoneVO) {
        return userService.registerByPhone(codePhoneVO);
    }

    /**
     * 邮箱注册
     *
     * @param codeEmailVo
     * @return
     */
    @PostMapping("/register/email")
    public Result registerByEmail(CodeEmailVo codeEmailVo) {
        return userService.registerByEmail(codeEmailVo);
    }

    /***
     * 登出账号
     * @return
     */
    @GetMapping("logout")
    public Result logout() {
        return userService.logout();
    }
}
